package jwei.apps.indextank;

import jwei.apps.indextank.adapters.RestaurantsCursorAdapter;
import jwei.apps.indextank.db.RestaurantCache.RestaurantsCache;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class BookmarkActivity extends ListActivity {

    private RestaurantsCursorAdapter rca;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bookmark_layout);

        // query for products
        Cursor c = getContentResolver().query(RestaurantsCache.CONTENT_URI, null, RestaurantsCache.IS_QUEUE + "=1",
                null, null);
        startManagingCursor(c);
        String[] from = new String[] { RestaurantsCache.NAME, RestaurantsCache.STREET };
        int[] to = new int[] { R.id.restaurant_name, R.id.restaurant_street };

        // set list adapter
        rca = new RestaurantsCursorAdapter(BookmarkActivity.this, R.layout.search_list_entry, c, from, to);
        setListAdapter(rca);

    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        if (rca == null) { return; }

        Cursor c = (Cursor) rca.getItem(position);

        Intent i = new Intent(BookmarkActivity.this, RestaurantDetailsActivity.class);
        String docid = c.getString(c.getColumnIndex(RestaurantsCache.DOC_ID));
        i.putExtra("docid", docid);
        i.putExtra("name", c.getString(c.getColumnIndex(RestaurantsCache.NAME)));
        i.putExtra("street", c.getString(c.getColumnIndex(RestaurantsCache.STREET)));
        i.putExtra("city", c.getString(c.getColumnIndex(RestaurantsCache.CITY)));
        i.putExtra("state", c.getString(c.getColumnIndex(RestaurantsCache.STATE)));
        i.putExtra("zip", c.getString(c.getColumnIndex(RestaurantsCache.ZIP)));
        i.putExtra("url", c.getString(c.getColumnIndex(RestaurantsCache.WEBSITE)));
        i.putExtra("phone", c.getString(c.getColumnIndex(RestaurantsCache.PHONE)));
        i.putExtra("tags", c.getString(c.getColumnIndex(RestaurantsCache.TAGS)));
        i.putExtra("dishes", c.getString(c.getColumnIndex(RestaurantsCache.DISHES)));
        i.putExtra("ingredients", c.getString(c.getColumnIndex(RestaurantsCache.INGREDIENTS)));
        startActivity(i);
    }

}
